package com.jyy.prefabricated.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jyy.prefabricated.common.AjaxResult;
import com.jyy.prefabricated.dto.Pageable;
import com.jyy.prefabricated.entity.PublicTransfer;
import com.jyy.prefabricated.service.PublicTransferService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 对公转账商户信息表(PublicTransfer)表控制层
 *
 * @author makejava
 * @since 2021-08-16 14:52:18
 */
@Slf4j
@RestController
@RequestMapping("/api")
public class PublicTransferController {
    /**
     * 服务对象
     */
    @Resource
    private PublicTransferService publicTransferService;

    /**
     * 新增对公转账商户信息
     *
     * @param publicTransfer
     * @return
     */
    @PostMapping("/public_transfer")
    public AjaxResult insert(@Valid @RequestBody PublicTransfer publicTransfer) {
        log.info("Rest request to insert publicTransfer:{}", publicTransfer);
        PublicTransfer result = publicTransferService.insert(publicTransfer);
        return AjaxResult.success(result);
    }

    /**
     * 更新对公转账商户信息
     *
     * @param PublicTransfer
     * @return
     */
    @PutMapping("/public_transfer")
    public AjaxResult update(@Valid @RequestBody PublicTransfer PublicTransfer) {
        log.info("Rest request to update PublicTransfer:{}", PublicTransfer);
        PublicTransfer result = publicTransferService.update(PublicTransfer);
        return AjaxResult.success(result);
    }

    /**
     * 查询对公转账商户信息详情
     *
     * @param id
     * @return
     */
    @GetMapping("/public_transfer/{id}")
    public AjaxResult selectById(@PathVariable Integer id) {
        log.info("Rest request to find PublicTransfer by id:{}", id);
        PublicTransfer result = publicTransferService.queryById(id);
        return AjaxResult.success(result);
    }

    /**
     * 删除对公转账商户信息
     *
     * @param id
     * @return
     */
    @DeleteMapping("/public_transfer/{id}")
    public AjaxResult deleteById(@PathVariable Integer id) {
        log.info("Rest request to delete PublicTransfer by id:{}", id);
        boolean row = publicTransferService.deleteById(id);
        if (row) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }

    /**
     * 分页查询对公转账商户信息
     *
     * @return
     */
    @GetMapping("/public_transfer")
    public AjaxResult selectByParams(PublicTransfer publicTransfer) {
        log.info("Rest request to find PublicTransfer by category:{}", publicTransfer);
        PageHelper.startPage(publicTransfer.getPageNum(), publicTransfer.getPageNum());
        List<PublicTransfer> publicTransferList = publicTransferService.queryAll(publicTransfer);
        PageInfo<PublicTransfer> result = new PageInfo<>(publicTransferList);
        return AjaxResult.success(result);
    }

    /**
     * 查询对公转账商户信息列表
     * @param publicTransfer 分类名称
     * @return
     */
    @GetMapping("/public_transfer-list")
    public AjaxResult selectList(PublicTransfer publicTransfer) {
        log.info("Rest request to find PublicTransfer by publicTransfer:{}",publicTransfer);
        List<PublicTransfer> result = publicTransferService.queryAll(publicTransfer);
        return AjaxResult.success(result);
    }

}
